import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { PayChannelService } from '../../services/admin/pay-channel.service';

/**
 * PayChannelController
 * 对应 PHP: PayChannel Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('pay')
@Controller('adminapi/pay')
export class PayChannelController {
  constructor(private readonly payChannelService: PayChannelService) {}

  /**
   * 支付渠道设置
   * 路由: POST channel/set/:channel/:type
   * PHP路由: Route::post('channel/set/:channel/:type', 'pay.PayChannel/set')
   */
  @Post('channel/set/:channel/:type')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '支付渠道设置' })
  async set(
    @Param('channel') channel: string,
    @Param('type') type: string,
    @Body() data: SetDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: set

      return await this.payChannelService.set(channel, type, data);
    } catch (error) {
      throw new BusinessException('set操作失败', error);
    }
  }

  /**
   * 支付渠道设置
   * 路由: GET channel/lists
   * PHP路由: Route::get('channel/lists', 'pay.PayChannel/lists')
   */
  @Get('channel/lists')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '支付渠道设置' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.payChannelService.getChannelList();
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 支付渠道设置
   * 路由: GET channel/lists/:channel
   * PHP路由: Route::get('channel/lists/:channel', 'pay.PayChannel/getListByChannel')
   */
  @Get('channel/lists/:channel')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '支付渠道设置' })
  async getListByChannel(
    @Param('channel') channel: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getListByChannel

      return await this.payChannelService.getListByChannel(channel);
    } catch (error) {
      throw new BusinessException('getListByChannel操作失败', error);
    }
  }

  /**
   * 支付渠道设置
   * 路由: POST channel/set/transfer
   * PHP路由: Route::post('channel/set/transfer', 'pay.PayChannel/setTransfer')
   */
  @Post('channel/set/transfer')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '支付渠道设置' })
  async setTransfer(@Body() data: SetTransferDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setTransfer

      return await this.payChannelService.setTransfer(data);
    } catch (error) {
      throw new BusinessException('setTransfer操作失败', error);
    }
  }

  /**
   * 支付渠道设置
   * 路由: POST channel/set/all
   * PHP路由: Route::post('channel/set/all', 'pay.PayChannel/setAll')
   */
  @Post('channel/set/all')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '支付渠道设置' })
  async setAll(@Body() data: SetAllDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: setAll

      return await this.payChannelService.setAll(data['config']);
    } catch (error) {
      throw new BusinessException('setAll操作失败', error);
    }
  }

  /**
   * 支付渠道设置
   * 路由: GET type/all
   * PHP路由: Route::get('type/all', 'pay.PayChannel/getPayTypeList')
   */
  @Get('type/all')
  @ApiOperation({ summary: '支付渠道设置' })
  async getPayTypeList() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getPayTypeList
      // 直接返回字典数据
      return PayDict.getPayType();
    } catch (error) {
      throw new BusinessException('getPayTypeList操作失败', error);
    }
  }
}
